package com.hzyb.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public  class FileUploadUtil {
	public static Map<String, Object> writeFile(byte[] is,String fileType,String suffix,String system_file_path) {
		Map<String, Object> map=new HashMap<>();
		map.put("status", "fail");
		File file=new File(system_file_path+fileType);
		if(!file.exists()) {
			file.mkdirs();
		}
		try {
			String filename=UUID.randomUUID().toString().replaceAll("-", "");
			FileOutputStream out= new FileOutputStream(system_file_path+fileType+"/"+filename+suffix);
			out.write(is);
			out.flush();
			out.close();
			map.put("status", "success");
			map.put("file_id",filename);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}
}
